home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / lisp / stk-3.002 / stk-3 / STk-3.1 / Src / tk-main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-23  |  4.8 KB  |  184 lines

  1. /* 
  2.  * t k - m a i n . c             -- Initialization of Tk
  3.  *
  4.  * This code initializes the Tk library. It corresponds to a part of the 
  5.  * file main.c of the wish interpreter. 
  6.  *
  7.  *           Author: Erick Gallesio [eg@unice.fr]
  8.  *    Creation date: 13-May-1993 10:59
  9.  * Last file update: 23-Jul-1996 16:45
  10.  *
  11.  *
  12.  * Code used here was originally copyrigthed as shown below:
  13.  *      Copyright 1990-1992 Regents of the University of California.
  14.  *
  15.  *
  16.  * Copyright ⌐ 1993-1996 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.fr>
  17.  * 
  18.  *
  19.  * Permission to use, copy, and/or distribute this software and its
  20.  * documentation for any purpose and without fee is hereby granted, provided
  21.  * that both the above copyright notice and this permission notice appear in
  22.  * all copies and derived works.  Fees for distribution or use of this
  23.  * software or derived works may only be charged with express written
  24.  * permission of the copyright holder.  
  25.  * This software is provided ``as is'' without express or implied warranty.
  26.  *
  27.  * This software is a derivative work of other copyrighted softwares; the
  28.  * copyright notices of these softwares are placed in the file COPYRIGHTS
  29.  *
  30.  */
  31. #ifdef USE_TK
  32. #include <signal.h>
  33. #include "stk.h"
  34.  
  35.  
  36. /*
  37.  * Command used to initialize wish:
  38.  */
  39.  
  40. static char initCmd[] = "(load (string-append *stk-library* \"/STk/tk-init.stk\"))";
  41.  
  42. /*
  43.  * Global variables used by the main program:
  44.  */
  45.  
  46. static Tk_Window w;            /* The main window for the application.  If
  47.                       * NULL then the application no longer
  48.                      * exists. */
  49. Tcl_Interp *STk_main_interp= NULL;    /* Interpreter for this application. */
  50. int Tk_initialized = 0;            /* 1 when Tk is fully initialized */
  51.  
  52. /*
  53.  * Forward declarations for procedures defined later in this file:
  54.  */
  55.  
  56. static void DelayedMap _ANSI_ARGS_((ClientData clientData));
  57. static void StructureProc _ANSI_ARGS_((ClientData clientData,
  58.                        XEvent *eventPtr));
  59.  
  60.  
  61. /*
  62.  *
  63.  * Tcl-main
  64.  *
  65.  *  Perhaps, this procedure should be made available outside and the
  66.  *  USE_TK conditionnal flags should be split in USE_TCL and USE_TK
  67.  *
  68.  */
  69.  
  70. static void Tcl_main(void)
  71. {
  72.   STk_main_interp = Tcl_CreateInterp();
  73.  
  74.   /* Initialize commands which are now in Tcl */
  75.   Tcl_CreateCommand(STk_main_interp, "after",  Tcl_AfterCmd, NULL, NULL);
  76.   Tcl_CreateCommand(STk_main_interp, "update", Tcl_UpdateCmd, NULL, NULL);
  77.  
  78.   /*
  79.    * Vwait command can always be done with (tkwait 'variable ...).
  80.    * So we don't define explicitely vwait 
  81.    * Note that "update" is also redefined by Tk4.1
  82.    *
  83.    * Tcl_CreateCommand(STk_main_interp, "vwait",  Tcl_VwaitCmd, NULL, NULL);
  84.    *
  85.    */
  86. }
  87.  
  88. /*
  89.  *----------------------------------------------------------------------
  90.  *
  91.  * Tk_main
  92.  *
  93.  *----------------------------------------------------------------------
  94.  */
  95.  
  96. void Tk_main(int synchronize, char *name, char *fileName, char *Xdisplay,
  97.          char *geometry)
  98. {
  99.   char *p, *Class;
  100.   int argc, code;
  101.   char *args[20];  
  102.  
  103.   Tcl_main();
  104.  
  105.   if (name == NULL) {
  106.     p    = (fileName != NULL) ? fileName: STk_Argv0;
  107.     name = strrchr(p, '/');
  108.     if (name != NULL) 
  109.       name++;
  110.     else 
  111.       name = p;
  112.   }
  113.  
  114.   /*
  115.    * Initialize the Tk application and arrange to map the main window
  116.    * after the startup script has been executed, if any.  This way
  117.    * the script can withdraw the window so it isn't ever mapped
  118.    * at all.
  119.    */
  120. #ifdef FIXME
  121.   Class = (char *) ckalloc((unsigned) (strlen(name) + 1));
  122.   strcpy(Class, name);
  123.   Class[0] = toupper((unsigned char) Class[0]); 
  124. #else
  125.   Class = "STk";
  126. #endif
  127.  
  128. #ifdef FIXME
  129.   ckfree(Class);
  130. #endif
  131.  
  132.   args[0] = "toplevel";
  133.   args[1] = ".";
  134.   args[2] = "-class";
  135.   args[3] = Class;
  136.   argc = 4;
  137.  
  138.   if (Xdisplay != NULL) {
  139.     args[argc] = "-screen";
  140.     args[argc+1] = Xdisplay;
  141.     argc += 2;
  142.   }
  143.  
  144.   if (STk_arg_colormap) {
  145.     args[argc]   = "-colormap";
  146.     args[argc+1] = "new";
  147.     argc += 2;
  148.   }
  149.   if (STk_arg_visual != NULL) {
  150.       args[argc] = "-visual";
  151.       args[argc+1] = STk_arg_visual;
  152.       argc += 2;
  153.   }
  154.   args[argc] = NULL;
  155.   
  156.   Tcl_ResetResult(STk_main_interp);
  157.  
  158.   code = TkCreateFrame((ClientData) NULL, STk_main_interp, argc, args, 1, name);
  159.   if (code != TCL_OK) {
  160.     panic(STk_main_interp->result);
  161.   }
  162.   
  163. #ifndef WIN32
  164.   if (synchronize) XSynchronize(Tk_Display(Tk_MainWindow(STk_main_interp)), TRUE);
  165. #endif
  166.   /* Set the geometry of the main window, if requested. */
  167.   if (geometry != NULL) {
  168.     if (TCL_OK != Tcl_VarEval(STk_main_interp, "(wm 'geometry *root* '", 
  169.                   geometry, ")", NULL))
  170.       fprintf(STk_stderr, "**** Warning: %s\n", STk_main_interp->result);
  171.   }
  172.   code = TkPlatformInit(STk_main_interp);
  173.   
  174.   if (code == TCL_OK)
  175.     Tk_initialized = 1;   /* Ok, it's fully initialized */
  176.   
  177.   STk_init_tracevar();     /* Initialize the variable tracing mechanism */
  178.   STk_init_glue();
  179.  
  180.   /* Execute STk's initialization script */
  181.   Tcl_GlobalEval(STk_main_interp, initCmd);
  182. }
  183. #endif /* USE_TK */
  184.